  // const API_HOST = ''
import md5 from 'js-md5'
import Public from './public'
const API_HOST = Public.api
var DATA = {
  token: 'sssdsds',
  timestamp: '',
  sign: '',
  bizId: 111,
  data: { },
  pager: {
    startNo: '',
    endNo: ''
  }
}
var tookingAryy = {
  // 查看托运
  findConsign: ({commit, state}, parm) => {
    var url = API_HOST + '/consign/getConsignByCityId'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('CommitFindConsign', res)
      }else {
        res.code = 1
        commit('CommitFindConsign', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  // 登陆
  adminLoginFn: ({commit, state}, userName) => {
    var url = API_HOST + '/admin/login'
    // 收集登陆参数
    var parm = {
      userName: userName.userName,
      passwd: md5(userName.password + 'IS8b9zvn')
    }
    // 获取当前时间戳
    var date = new Date()
    var time = date.getTime()
    // 获取当前token
    DATA.token = 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJsb2dpbiIsImlhdCI6MTUxMzA3NDEyMSwic3ViIjoiLTEiLCJleHAiOjE1MTQ1NDUzNTAsIm5iZiI6MTUxMzA3NDEyMX0.Zc88CxsE8n_N5BNj9zMWH9zyENksT1IfdGcaKmjGGkY'
    DATA.timestamp = time
    DATA.data = parm
    // parm = '{"userName":"ivan","passwd":"e833c14c7f490a431519cb0919407a7c"}'
    var dat = JSON.stringify(parm).split('').sort().join('').split('"').join('')
    DATA.sign = md5(DATA.token + DATA.timestamp + dat)
    //console.log(md5('{"token":"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJsb2dpbiIsImlhdCI6MTUxMzA3NDEyMSwic3ViIjoiLTEiLCJleHAiOjE1MTQ1NDUzNTAsIm5iZiI6MTUxMzA3NDEyMX0.Zc88CxsE8n_N5BNj9zMWH9zyENksT1IfdGcaKmjGGkY","timestamp":1514453207776,"sign":"824d925397958069ea516450eaaf4028","bizId":111,"data":{"userName":"ivan","passwd":"e833c14c7f490a431519cb0919407a7c"},"pager":{"startNo":0,"endNo":0}}'))
    // console.log(JSON.stringify(DATA))
    state.http.post(url, JSON.stringify(DATA), { emulateJSON: true }).then(function (res) {
      res.code='login'
      commit('updateUser', res)
    }).catch(function (res) {
      var parm ={
        body:{
          code:'loginError',
          statu:-1
        },
      }
      commit('updateUser', parm)
    })
  },
  // 登陆
  loginFn: ({commit, state}, userName) => {
    var url = API_HOST + '/user/login'
    // 收集登陆参数
    var parm = {
      userName: userName.userName,
      passwd: md5(userName.password + 'IS8b9zvn')
    }
    // 获取当前时间戳
    var date = new Date()
    var time = date.getTime()
    // 获取当前token
    DATA.token = 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJsb2dpbiIsImlhdCI6MTUxMzA3NDEyMSwic3ViIjoiLTEiLCJleHAiOjE1MTQ1NDUzNTAsIm5iZiI6MTUxMzA3NDEyMX0.Zc88CxsE8n_N5BNj9zMWH9zyENksT1IfdGcaKmjGGkY'
    DATA.timestamp = time
    DATA.data = parm
    // parm = '{"userName":"ivan","passwd":"e833c14c7f490a431519cb0919407a7c"}'
    var dat = JSON.stringify(parm).split('').sort().join('').split('"').join('')
    DATA.sign = md5(DATA.token + DATA.timestamp + dat)
    //console.log(md5('{"token":"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJsb2dpbiIsImlhdCI6MTUxMzA3NDEyMSwic3ViIjoiLTEiLCJleHAiOjE1MTQ1NDUzNTAsIm5iZiI6MTUxMzA3NDEyMX0.Zc88CxsE8n_N5BNj9zMWH9zyENksT1IfdGcaKmjGGkY","timestamp":1514453207776,"sign":"824d925397958069ea516450eaaf4028","bizId":111,"data":{"userName":"ivan","passwd":"e833c14c7f490a431519cb0919407a7c"},"pager":{"startNo":0,"endNo":0}}'))
    state.http.post(url, JSON.stringify(DATA), { emulateJSON: true }).then(function (res) {
      res.code='login'
      commit('updateUser', res)
    })
  },
  // 验证码
  sendAuth:({commit, state}, parm) => {
    var url = API_HOST+"/user/sendAuth"
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitSendAuth', res)
    }).catch(function (res) {
      commit('commitSendAuth', null)
    })
  },
  //注册
  register:({commit, state}, parm) => {
    var url = API_HOST + '/user/register'
    parm.password = md5(parm.password+ 'IS8b9zvn')
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.code='register'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateStatusTo', null)
    })
  },
  //注册
  forgotPwd:({commit, state}, parm) => {
    var url = API_HOST + '/user/forgotPwd'
    parm.newPwd = md5(parm.newPwd+ 'IS8b9zvn')
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.code='register'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateStatusTo', null)
    })
  },
  // 重置密码
  changePwd: ({commit, state}, parm) => {
    var url = API_HOST + '/user/changePwd'
    parm.oldpwd = md5(parm.oldpwd + 'IS8b9zvn')
    parm.newpwd = md5(parm.newpwd + 'IS8b9zvn')
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 0
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = -1
      commit('updateUserList', null)
    })
  },
  // 更新个人信息
  changeInfo: ({commit, state}, parm) => {
    var url = API_HOST + '/user/changeInfo'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.code='changeInfo'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      commit('updateStatusTo', null)
    })
  },
  // 查看个人信息
  getInfo: ({commit, state}, parm) => {
    var url = API_HOST + '/user/getInfo'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.code='userInfo'
      commit('commitUserInfo', res)
    }).catch(function (res) {
      commit('commitUserInfo', null)
    })
  },

  // 退出登陆
  loginOutFn: ({commit, state}, parm) => {
    var url = API_HOST + '/user/logout'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateStatusTo', {body: 'out'})
    }).catch(function (res) {
      commit('updateStatusTo', {body: 'outErorr'})
    })
  },
  // 条件搜索
  searchList: ({commit, state}, parm) => {
    var url = API_HOST + '/transitLine/findLines'
    var data = Public.publicLo.parmToken(parm)
    // parm = JSON.stringify(parm)

    state.http.post(url, data).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  //首页推荐
  recommendLines: ({commit, state}, parm) => {
    var url = API_HOST + '/transitLine/recommendLines'
    var data = Public.publicLo.parmToken(parm)
    // parm = JSON.stringify(parm)

    state.http.post(url, data).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('recommendLinesListTo', res)
      }else {
        res.code = 1
        commit('recommendLinesListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('recommendLines', res)
    })
  },
  // 询价单详情
  quotationDetails: ({commit, state}, parm) => {
    var url = API_HOST + '/enquiry/quotation/quotationDetails'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
// console.log(data,'dat')
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitBizDetails', res)
    }).catch(function (res) {
      commit('commitBizDetails', null)
    })
  },
//询价单列表
  showQuotationList: ({commit, state}, parm) => {
    var url = API_HOST + '/enquiry/quotation/showQuotationList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)

    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitUpdateList', res)
    }).catch(function (res) {
      commit('commitUpdateList', null)
    })
  },

  sadmiShowList: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/showList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    // console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitUpdateList', res)
    }).catch(function (res) {
      commit('commitUpdateList', null)
    })
  },
  //添加 额外费用
  addCost: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/addCost'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)

    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'addCost'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'addCost'
      commit('updateStatusTo', {body: null})
    })
  },
  // 线路详情
  getLineDetail: ({commit, state}, parm) => {
    var url = API_HOST + '/transitLine/getLineDetail'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data);
    // console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('updateDetail', res)
    }).catch(function (res) {
      commit('updateDetail', null)
    })
  },
  // 支持的城市
  getCityList: ({commit, state}, parm) => {
    var url = API_HOST + '/user/company/cityList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      commit('commitCityList', res)
    }).catch(function (res) {
      commit('commitCityList', null)
    })
  },
  // 查询价格
  findQuotation: ({commit, state}, parm) => {
    var url = API_HOST + '/valuation/findQuotation'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
// console.log(data )
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.code = 'Quotation'
      commit('commitQuotation', res)
    }).catch(function (res) {
      var parm={status:400,code:'error'}
      commit('commitQuotation', parm)
    })
  },
  //添加询价单
  addQuotation: ({commit, state}, parm) => {
    var url = API_HOST + '/enquiry/quotation/addQuotation'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)

    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'addQuotation'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'addQuotation'
      commit('updateStatusTo', res)
    })
  },
  //修改询价单金额
  modifyQuotationOrderDetail: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/modifyQuotationOrderDetail'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    // console.log(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'modifyQuotationOrderDetail'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'modifyQuotationOrderDetail'
      commit('updateStatusTo', res)
    })
  },
  //删除询价单额外金额
  deleteCost: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/deleteCost'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'deleteCost'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'deleteCost'
      commit('updateStatusTo', res)
    })
  },
  modifyQuotationOrderStatus: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/modifyQuotationOrderStatus'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      res.body.code = 'modifyQuotationOrderStatus'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'modifyQuotationOrderStatus'
      commit('updateStatusTo', res)
    })
  },

  //查看拖车城市
  getProvinceAndCity: ({commit, state}, parm) => {
    var url = API_HOST + '/consign/getProvinceAndCity'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('commitgetProvinceAndCity', res)
    }).catch(function (res) {
      commit('commitgetProvinceAndCity', null)
    })
  },
// 查询拖车城市
  getLineQuotationSupport: ({commit, state}, parm) => {
    var url = API_HOST + '/lineQuotation/findLineQuotationSupport'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('commitfindLineQuotationSupport', res)
    }).catch(function (res) {
      commit('commitfindLineQuotationSupport', null)
    })
  },
// 限制重量
  findLineWeightConfine: ({commit, state}, parm) => {
    var url = API_HOST + '/lineWeightConfine/findLineWeightConfine'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('commitWeightConfine', res)
    }).catch(function (res) {
      commit('commitWeightConfine', null)
    })
  },
//拼箱城市
  getDestStationCity: ({commit, state}, parm) => {
    var url = API_HOST + '/transitLine/getDestStationCity'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('commitDestStationCity', res)
    }).catch(function (res) {
      commit('commitDestStationCity', null)
    })
  },
  csuserList: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/csuserList'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      commit('commitCsuserList', res)
    }).catch(function (res) {
      commit('commitCsuserList', null)
    })
  },
  modifyQuotationOrderCsuser: ({commit, state}, parm) => {
    var url = API_HOST + '/admin/order/modifyQuotationOrderCsuser'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      res.body.code = 'modifyQuotationOrderCsuser'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'modifyQuotationOrderCsuser'
      commit('updateStatusTo', null)
    })
  },
  // 校验手机号
  phoneIsExist: ({commit, state}, parm) => {
    var url = API_HOST + '/user/phoneIsExist'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      res.body.code = 'phoneIsExist'
      commit('updateStatusTo', res)
    }).catch(function (res) {
      res.body.code = 'phoneIsExist'
      commit('updateStatusTo', null)
    })
  },
  // 提箱点
  getSuitcasePoint: ({commit, state}, parm) => {
    var url = API_HOST + '/consign/getSuitcasePoint'
    var data = Public.publicLo.parmToken(parm)
    data = JSON.stringify(data)
    state.http.post(url, data, { emulateJSON: true }).then(function (res) {
      //通过 commit addMapList 方法 统一注入sate
      res.body.code = 'getSuitcasePoint'
      commit('commitSuitcasePoint', res)
    }).catch(function (res) {
      res.body.code = 'getSuitcasePoint'
      commit('commitSuitcasePoint', null)
    })
  },
  // 拼箱
  lclFindLines: ({commit, state}, parm) => {
    var url = API_HOST + '/transitLine/lcl/findLines'
    var data = Public.publicLo.parmToken(parm)
    // parm = JSON.stringify(parm)
    state.http.post(url, data).then(function (res) {
      // code 用于判断 当前数据状态 0：正常，1：接口成功但数据集合为[ ] 空，-1：接口请求失败
      if(res.body.data.length >= 1){
        res.code = 0
        commit('transportListTo', res)
      }else {
        res.code = 1
        commit('transportListTo', res)
      }
    }).catch(function (res) {
      res.code = -1
      commit('transportListTo', res)
    })
  },
  }
export default {tookingAryy}

